package com.zhgxi.zf.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.zhgxi.zf.entity.Event;
import com.zhgxi.zf.entity.User;
import com.zhgxi.zf.service.EventService;

@Controller("EventAction")
public class EventAction {
	@Resource
	private EventService eventService;

	public Boolean saveEvent(Event event) {
		return eventService.saveEvent(event);
	}

	public List<Event> findAll(boolean isemergency,User user) {
		return eventService.findAllEvent(isemergency,user);

	}

	public List<Event> findAll() {

		return eventService.findAllEvent();

	}

	public List<Event> searchEventByName(String ename, boolean isemergency,User user) {
		return eventService.searchEventByName(ename, isemergency,user);
	}

	public boolean deleteEvent(Event event) {
		return eventService.delEvent(event);
	}

	@InitBinder
	public void InitBinder(WebDataBinder dataBinder) {
		dataBinder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), false));
	}

	/**
	 * @author elemeNT
	 * @param list
	 * @return
	 */
	public List<Event> search(List<HashMap<String, String>> list) {
		HashMap<String, String> newMap = new HashMap<String, String>();
		for (HashMap<String, String> hashMap : list) {
			newMap.put(hashMap.get("key"), hashMap.get("value"));
		}
		return eventService.searchEvent(newMap);
	}

}
